/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package control;

import java.awt.Color;
import javax.swing.JLabel;
import view.BrugerLogin;
import view.GUI;
import view.Kasse;
import view.Lager;
import view.Print;
import view.Statistik;

/**
 *
 * @author Morten J, Morten B & Jonas
 */
public class GuiHandler {

    private final GUI gu;
    private final BrugerLogin bl;
    private final Lager lg;
    private final Kasse ks;
    private final Statistik st;
    private Print pr;
    private static JLabel aktuelLabel;

    public GuiHandler(GUI gu, BrugerLogin bl, Lager lg, Kasse ks, Statistik st) {
        this.gu = gu;
        this.bl = bl;
        this.ks = ks;
        this.lg = lg;
        this.st = st;
        showBrugerlogin();
    }

    public static JLabel getAktuelLabel() {
        return aktuelLabel;
    }

    public static void setAktuelLabel(JLabel aktuelLabel) {
        GuiHandler.aktuelLabel = aktuelLabel;
    }

    public void toogleLogOut(boolean state) {
        gu.toogleLogOut(state);
    }

    public void closeWindows() {
        if (lg.isVisible()) {
            lg.setVisible(false);
        }
        if (bl.isVisible()) {
            bl.setVisible(false);
        }
        if (ks.isVisible()) {
            ks.setVisible(false);
        }
        if (st.isVisible()) {
            st.setVisible(false);
        }
    }

    public void setLoginFeedback(String feedback) {
        bl.setFeedbackMessage(feedback);
    }

    public final void showBrugerlogin() {
        closeWindows();
        bl.setVisible(true);
        setAktuelLabel(bl.getLabel());
    }

    public void showLager() {
        closeWindows();
        lg.setVisible(true);
        Lager.lh.searchStock(lg.getsString());
        lg.setStringFocus();
        lg.clearFeedback();
        setAktuelLabel(lg.getLabel());
    }

    public void showKasse() {
        closeWindows();
        ks.setVisible(true);
        ks.clearFeedback();
        setAktuelLabel(ks.getLabel());
    }

    public void showStatistik() {
        closeWindows();
        st.setVisible(true);
        st.clearFeedback();
        setAktuelLabel(st.getLabel());
    }

    public void showPrint(int fakturanr) {
        pr = new Print(fakturanr);
        pr.setText(FakturaHandler.faktura.toString());
        pr.setVisible(true);
    }

    public void setNavVisible(boolean e) {
        gu.setNavVisible(e);
    }

    public void setIndtastetVare(String nr) {
        ks.setIndtastetVare(nr);
    }

    public void setAnsatNavn() {
        gu.setAnsatNavn();
    }

    public void focusKasse() {
        ks.focusKasse();
    }

    public void setFeedbackMessage(String error, Color color) {
        getAktuelLabel().setForeground(color);
        getAktuelLabel().setText(error);
    }

    public void setFeedbackMessage(String error) {
        setFeedbackMessage("Forbindelse til databasen mislykkedes" + error + ". Genstart programmet", Main.getRED_COLOR());
    }

    public void clearKasse() {
        ks.clearKasse();
    }
}
